<?php

namespace Kunfeng\Dify\Model\Datasets;

/**
 * 分段规则
 */
class Segmentation
{
    private $separator;
    private $maxTokens;

    public function __construct(array $data = [])
    {
        $this->separator = $data['separator'] ?? "\n";
        $this->maxTokens = $data['max_tokens'] ?? 1000;
    }

    /**
     * 从数组创建
     */
    public static function fromArray(array $data): self
    {
        return new self($data);
    }

    /**
     * 创建分段规则
     */
    public static function create(string $separator = "\n", int $maxTokens = 1000): self
    {
        return new self(['separator' => $separator, 'max_tokens' => $maxTokens]);
    }

    // Getters
    public function getSeparator(): string
    {
        return $this->separator;
    }

    public function getMaxTokens(): int
    {
        return $this->maxTokens;
    }

    /**
     * 转换为数组
     */
    public function toArray(): array
    {
        return [
            'separator' => $this->separator,
            'max_tokens' => $this->maxTokens,
        ];
    }
}
